﻿using System.Reflection.Metadata.Ecma335;

int number = 5;
int anotherNumber = number;
anotherNumber++;

Console.WriteLine("Number is:" + number);
Console.WriteLine("Another number is:" + anotherNumber);

var john = new Person { Name = "John", Age = 24 };
var person = john;
person.Age = 34;

Console.WriteLine("John's age is" + john.Age);
Console.WriteLine("person's age is" + person.Age);

AddOneToNumber(ref number);
Console.WriteLine("Now the number is:" + number);


MethodWithoutParameter(out int otherNumber);
Console.WriteLine("other number is:" + otherNumber);

var list = new List<int> { 1, 2, 3 };
AddOneToList(ref list);


var variousObjects = new List<object>
{
    1,
    1.5m,
    new DateTime(2024, 1, 2),
    "hello",
    new Person { Name = "jack", Age = 22 }
};

foreach (var item in variousObjects)
{
    Console.WriteLine(item + item.GetType().Name);
}

const string csvPath = @"d:\sampleData.csv";
var data = new CsvReader().Read(csvPath);



Console.ReadKey();

void AddOneToList(ref List<int> numbers)
{
    numbers.Add(1);
}

void AddOneToNumber(ref int number)
{
    ++number;
}


void MethodWithoutParameter(out int number)
{
    number = 10;
}


class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}


public class CsvReader
{
    public CsvData Read(string path)
    {
        using var streamReader = new StreamReader(path);
        const string Separator = ",";
        var columns = streamReader.ReadLine().Split(Separator);

        var rows = new List<string[]>();
        while (!streamReader.EndOfStream)
        {
            var cellsInRow = streamReader.ReadLine().Split(Separator);
            rows.Add(cellsInRow);
        }

        return new CsvData(columns, rows);
    }
}

public class CsvData
{
    public string[] Columns { get; set; }
    public IEnumerable<string[]> Rows { get; set; }

    public CsvData(string[] columns,IEnumerable<string[]> rows)
    {
        Columns = columns;
        Rows = rows;
    }
}